#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Author  :   JingV
@Version :   1.0
@Contact :   None
@License :   None
@Desc    :   None
'''


class Solution(object):
    def partitionLabels(self, S):
        result, index, len_S = [], 0, len(S)
        while index < len_S:
            last_char_index = self.find_last_char_index(index, len_S-1, S)
            if last_char_index == -1:
                index += 1
                result.append(1)
            else:
                left = index + 1
                while True:
                    temp = self.find_last_char_index(left, len_S - 1, S)
                    if temp != -1 and last_char_index < temp:
                        last_char_index = temp
                    left += 1
                    if left >= last_char_index:
                        break
                result.append(last_char_index - index + 1)
                index = last_char_index + 1
        return result

    def find_last_char_index(self, start, end, S):
        for i in range(end, start, -1):
            if S[i] == S[start]:
                print(i)
                print(S[i])
                return i
        return -1


def main():
    solution = Solution()
    tests = ["eccbbbbdec"]
    for S in tests:
        print(solution.partitionLabels(S))


if __name__ == "__main__":
    main()
